package org.upt.dcda.webservices;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.upt.dcda.db.TagEntity;
import org.upt.dcda.presentation.TagInformation;

@Path("/services/tags/")
public class TagServices extends CommonService
{

	@GET
	@Path("getAllTags")
	public String getAllTags() throws Exception
	{
		try
		{
			TagInformation ti = new TagInformation();
			List<TagEntity> t = ti.getAllTags();

			ArrayList<String> tags = new ArrayList<String>();
			for (TagEntity tagEntity : t)
			{
				tags.add(tagEntity.getTagName());
			}

			Collections.sort(tags);
			return gson.toJson(tags);
		}
		catch (Throwable t)
		{
			logger.error("Caught " + t.getClass() + ": " + t, t);
			throw new Exception("Cannot complete request");
		}

	}
}
